package com.zklh.book.system.repo.impl;

import com.zklh.book.system.enums.UserRoleEnum;
import com.zklh.book.system.model.User;
import com.zklh.book.system.repo.UserRepo;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 用户持久层 repo
 *
 * @author 坐看落花
 * @version 1.0
 * @date 2021/3/20 19:29
 */
public class UserRepoImpl implements UserRepo {

    private Map<String,User> userStore = new LinkedHashMap<>();
    {
        userStore.put("tongting",new User("tingtong", "123456", "童婷婷", UserRoleEnum.CONSUMER.getKey(), 25, new ArrayList<>()));
        userStore.put("tongnan",new User("tongnan", "123456", "童楠", UserRoleEnum.CONSUMER.getKey(), 24, new ArrayList<>()));
        userStore.put("tongyifeng",new User("tongyifeng", "123456", "童一峰", UserRoleEnum.CONSUMER.getKey(), 23, new ArrayList<>()));
        userStore.put("admin",new User("admin", "123456", "管理员", UserRoleEnum.ADMIN.getKey(), 25, new ArrayList<>()));
    }

    @Override
    public User get(String account) {
        return userStore.get(account);
    }

    @Override
    public void save(User user) {
        if (userStore.get(user.getAccount()) == null) {
            return;
        }
        userStore.put(user.getAccount(),user);
    }
}
